<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <base href="<%=basePath%>">
    <title>登录</title>
    <link rel="stylesheet" href="css/login.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" /> 
</head>
<!--[if lt IE 9]>
	<div style="color:red;background:#faebcc;font-size:18px;text-align:center;height:50px;line-height:50px">
	    <span style="padding:2px 10px;font-size:14px;line-height:21px;display:inline-block;border-radius:50%;background:red;color:#fff;">!</span>
	    &nbsp;&nbsp;温馨提示，您当前使用的浏览器版本过低，为了更好的使用体验，请使用Chrome浏览器，<a href='https://www.baidu.com/link?url=A_hto3cmeMEd-wC3aaawbzT5_GqMiraKd3aeqcyHfcnQT-5JjXn62wKxl4uCntXRDw5f1xgtoYtlj9yHYquYSEAZzsW_YWJJFtfG-wBDpqu&wd=&eqid=d77cdd9c000438c1000000035729bb59' target='_blank'>点此下载</a>
	</div>
	<![endif]-->
<body>
<!--header-->
	<script src="js/custom.modernizr.js"></script>
<header>
  <ul class="head clearfix"><li class="title_img"></li></ul> 
</header>
<!--main-->
<div class="denglu_main">
    <ul class="clearfix">
        <li class="username">
            <input id="loginname" type="text" title="输入账号" placeholder="输入账号" value="" >
        </li>
        <li class="username2 username">
            <input id="password" type="password" title="输入密码" placeholder="输入密码" value="" >
        </li>
        <li class="jizhumima clearfix">
			<div class="jizhumima_left">
				<input type="checkbox" tabindex="4" id="savestate" onclick="savePaw();" checked="checked" node-type="savestate">
				<label for="savestate" >记住密码</label>
			</div>
           <!--  <a href="user/forgetPassword.do">忘记密码？</a> -->
        </li>
        <li class="yanzhengma clearfix">
			<div class="yanzhengma_left clearfix">
				<input id="code" type="text" title="输入验证码" placeholder="验证码" value="" style="color: black;" >
				<img id="codeImg" alt="点击更换" title="点击更换" style="width:109px;height:34px;margin-left:10px;cursor:pointer"  />
			</div>
            <a href="javascript:void(0);" onclick="javascript:changeCode();">换一换</a>
        </li>
        <li class="denglu_button">
            <input id="login" type="button" tabindex="6" onclick="severCheck();" style="cursor:pointer"  value="立即登录">
        </li>
    </ul>
</div>
</body>
<!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="js/jquery.tips.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript">
jQuery(function() {
	var loginname = $.cookie('loginname');
	var password = $.cookie('password');
	var type = $.cookie('type');
	if (typeof(loginname) != "undefined"
			&& typeof(password) != "undefined") {
		$("#loginname").val(loginname);
		$("#password").val(password);
		$("#savestate").attr("checked", true);
		$("#code").focus();
		if(type==1){
			 $("input[name='type']:eq(1)").attr("checked","checked");
		}
	}
});
document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
     if(e && e.keyCode==13){ // enter 键
         $("#login").trigger("click");
    }
}; 
$(document).ready(function() {
	changeCode();
	$("#codeImg").bind("click", changeCode);
});
function changeCode() {
	$("#codeImg").attr("src", "code?t=" + genTimestamp());
	
}
function genTimestamp() {
	var time = new Date();
	return time.getTime();
};
//服务器校验
function severCheck(){
	if(check()){
		var account = $("#loginname").val();
		var password = $("#password").val();
		var code =$("#code").val();
		$.ajax({
			url: 'adminGetAccount',
			type: "POST",
	    	data: {code:code,account:account,password:password},
	    	 dataType:"json",
			success: function(data){
				if("success" == data){
					saveCookie();
					 window.location.href="applyList";

				}else if("usererror" == data){
					$("#loginname").tips({
						side : 1,
						msg : "用户名或密码有误",
						bg : '#FF5080',
						time : 5
					});
					$("#loginname").focus();
				} else if("codeerror" == data){
					$("#code").tips({
						side : 1,
						msg : "验证码输入有误",
						bg : '#FF5080',
						time : 5
					});
					$("#code").focus();
				}else{
					$("#loginname").tips({
						side : 1,
						msg : "缺少参数",
						bg : '#FF5080',
						time : 5
					});
					$("#loginname").focus();
				}
			}
		});
	}
};
//客户端校验
function check() {
	if ($("#loginname").val() == "") {
			$("#loginname").tips({
				side : 2,
				msg : '帐号不得为空',
				bg : '#AE81FF',
				time : 3
			});
	
			$("#loginname").focus();
				return false;
		} else {
			$("#loginname").val(jQuery.trim($('#loginname').val()));
		}
	
		if ($("#password").val() == "") {
	
			$("#password").tips({
				side : 2,
				msg : '密码不得为空',
				bg : '#AE81FF',
				time : 3
			});
	
			$("#password").focus();
			return false;
		}
		if ($("#code").val() == "") {
	
			$("#code").tips({
				side : 1,
				msg : '验证码不得为空',
				bg : '#AE81FF',
				time : 3
			});
	
			$("#code").focus();
			return false;
		}

		return true;
	};

	function savePaw() {
		if (!$("input[type='checkbox']").is(':checked')) {
			$.cookie('loginname', '', {
				expires : -1
			});
			$.cookie('password', '', {
				expires : -1
			});
		}
	};

	function saveCookie() {
		if ($("input[type='checkbox']").is(':checked')) {
			$.cookie('loginname', $("#loginname").val(), {expires : 7 });
			$.cookie('password', $("#password").val(), {
				expires : 7
			});
			$.cookie('type', $("input[name='type']:checked").val(), {
				expires : 7
			});
		}
	};
	//TOCMAT重启之后 点击左侧列表跳转登录首页 
	if (window != top) {
		top.location.href = location.href;
	}
</script>
</html>